package com.lsj.gulimall.product.web;

import com.lsj.gulimall.product.entity.CategoryEntity;
import com.lsj.gulimall.product.service.CategoryService;
import com.lsj.gulimall.product.vo.CategoryTwoVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author 梁胜君
 * @version 1.0
 * @create 2022/3/22 7:48
 */
@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;


    @RequestMapping(value = {"/","/index"})
    public String index(Model model){
        List<CategoryEntity> categorys = categoryService.getCategoryLevel1();
        model.addAttribute("list",categorys);
        return "index";
    }

    @GetMapping("/index/json/catalog.json")
    @ResponseBody
    public Map<String,List<CategoryTwoVo>> getLevel1NextCategory(){
        Map<String,List<CategoryTwoVo>> map = categoryService.getCatalogJson();
        return map;
    }
}
